<?php
    require_once(MODEL_PATH.'/CMS/Base.php');
    require_once(LIB_PATH.'/HTMLComponent.php');
    
    class Model_CMS_Helper extends MODEL_CMS_Base{
    
        function __construct(){
        }
        
        function json_photo($photo){
        	return $this->single_photo($photo);
        }
        
        function single_photo($photo){
        	$image2='';
        	$size1='';
        	$size2='';
        	
        	if ($photo == ''){
        		return 'No Photo';
        	}
        	
        	
        	$html  = '<script type="text/javascript">';
        	$html .= "CMS.image_uplaod.show('$photo','$image2',";
        	$html .= "'$size1','$size2'); </script>";
        	return $html;
        }
        
        function photo($h_row, $fieldname='photo'){

       	  global $site_global_config;        	
          $front_end_url = $site_global_config['FRONT_END_URL'];

        	$image1 = $front_end_url.$h_row[$fieldname.'_image1'];
        	$image2 = $h_row[$fieldname.'_image2'];
          $size1  = $h_row[$fieldname.'_imagesize1'];
          $size2  = $h_row[$fieldname.'_imagesize2'];



        	$html  = '<script type="text/javascript">';
        	$html .= "CMS.image_uplaod.show('$image1','$image2',";
        	$html .= "'$size1','$size2'); </script>";
        	return $html;
        }
       
      function url($url){
      	 return html_link($url, $url, array('openwin'=>1));
      }
       
      function format_json_as_text($type, $json_data, $h_label){
   	    if ($type == 'hash') return $this->format_json_hash_as_text($json_data, $h_label);
      }
  

       
       
      function format_json_hash_as_text($json_data, $h_label){
        $json_decoded  = json_decode($json_data, true); 
  
        $a_result = array();
  
      	foreach ($json_decoded as $k => $v){
      	  if (isset($h_label[$k])){
      	  	$temp = $h_label[$k];
      	  	$label = '';
      	  	$value = '';
      	  	if (is_array($temp)){
      	  		
      	  		$label = $h_label[$k]['label'];
      	  		$function = $h_label[$k]['function'];
              $value = call_user_func_array(array($this, $function), array($v));
      
      	  	} else {
      	  		$label = $h_label[$k];
      	  		$value = $v;
      	  	}
      	  	
      	    array_push($a_result, $label." : ".$value); 
      	  } else {
      	    array_push($a_result, $k." : ".$v); 
      	  }
        }
        return implode("<BR/>", $a_result).'<BR><span style="color:#eee;">'.$json_data.'</span>';
      }

       
       
       
      
} // end class
    
?>